package com.hoangkien.soundcloud.activity;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import com.hoangkien.soundcloud.R;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sound.service.MyService;
import com.sound.service.MyService.LocalBinder;

public class PlayMusicActivity extends Activity {
	
	private SlidingUpPanelLayout mLayout;
	
	private MyService myService;
	private boolean mBound;
	ServiceConnection connection = new ServiceConnection() {
		@Override
		public void onServiceDisconnected(ComponentName name) {
			mBound = false;
			myService = null;
		}
		
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			mBound = true;
			LocalBinder binder = (LocalBinder) service;
			myService = binder.getMyService();
		}
	};

	public static void actionLaunch(Context context) {
		Intent intent = new Intent(context, PlayMusicActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_play_music);
		mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
		mLayout.showPanel();
		findViewById(R.id.play).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				myService.playMusic();
			}
		});
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		Intent intent = new Intent(PlayMusicActivity.this, MyService.class);
		bindService(intent, connection, BIND_AUTO_CREATE);
	}

}
